﻿#ifndef UDPMSGPROCESS_H
#define UDPMSGPROCESS_H

#include <QObject>
#include <QUdpSocket>
#include <QByteArray>
#include <QDebug>
#include <QDataStream>
#include <savelogthread.h>
#include <QDateTime>
#include <cglobals.h>
#include <general.h>
#include <QTimer>


class UdpMsgProcess : public QObject
{
    Q_OBJECT
public:
    explicit UdpMsgProcess(QObject *parent = nullptr);
    ~UdpMsgProcess();
    bool bind(SYSTEM local, SYSTEM remote);
    void setCurrentCycle(pCYCLE_ATTR pCycle);
    void regularSave(QString filePath);
    void setRegularSaveTime(int time);
    void setCommonParameters(pCOMMONS pCommon);
    void startReceive();


public slots:
    void slotReadyRead();
    void stopReceive();
    void slotSaveLog();

signals:
    void startsave(QString logname, QVector<QByteArray*>* pReceivedData);
    void receivedData(QByteArray* pData);
    void setFlag(bool flag);
    void startReq();


private:
    QThread _thread;
    QUdpSocket _socket;
    pCYCLE_ATTR pCycle;
    QVector<QByteArray*>* pReceivedData = NULL;
    QVector<QByteArray*>* pReceivedDataBak = NULL;
    int* regularTime;
    QString* filePath;
    bool* bakdata;
    QString* logname;
    pCOMMONS pCommon;
    SaveLogThread* threadSaveLog;
    QTimer _timer;
    QString remote_ip;
    qint32 remote_port;
    bool isStarted = false;

};

#endif // UDPMSGPROCESS_H
